﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace WAI
{
    public class Step_LicenseFile : InternalWizardPage
    {
        private Label label1;
        private TextBox textBox1;
        private Button browse;
        private Button load;
        private RichTextBox richTextBox1;
        private System.ComponentModel.IContainer components = null;

        public Step_LicenseFile()
        {
            // This call is required by the Windows Form Designer.
            InitializeComponent();

            // TODO: Add any initialization after the InitializeComponent call
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

        #region Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.browse = new System.Windows.Forms.Button();
            this.load = new System.Windows.Forms.Button();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.SuspendLayout();
            // 
            // Banner
            // 
            this.Banner.Size = new System.Drawing.Size(811, 64);
            this.Banner.Subtitle = "Please select your license file (must be rtf format)";
            this.Banner.Title = "License File";
            // 
            // label1
            // 
            this.label1.AutoSize = true;
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
            this.label1.Location = new System.Drawing.Point(28, 90);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(99, 13);
            this.label1.TabIndex = 1;
            this.label1.Text = "License File (rtf)";
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(133, 87);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(494, 20);
            this.textBox1.TabIndex = 2;
            // 
            // browse
            // 
            this.browse.Location = new System.Drawing.Point(650, 85);
            this.browse.Name = "browse";
            this.browse.Size = new System.Drawing.Size(75, 23);
            this.browse.TabIndex = 3;
            this.browse.Text = "Browse";
            this.browse.UseVisualStyleBackColor = true;
            this.browse.Click += new System.EventHandler(this.browse_Click);
            // 
            // load
            // 
            this.load.Location = new System.Drawing.Point(133, 113);
            this.load.Name = "load";
            this.load.Size = new System.Drawing.Size(75, 23);
            this.load.TabIndex = 4;
            this.load.Text = "Load File";
            this.load.UseVisualStyleBackColor = true;
            this.load.Click += new System.EventHandler(this.load_Click);
            // 
            // richTextBox1
            // 
            this.richTextBox1.Location = new System.Drawing.Point(31, 142);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(748, 353);
            this.richTextBox1.TabIndex = 5;
            this.richTextBox1.Text = "";
            // 
            // Step_LicenseFile
            // 
            this.Controls.Add(this.richTextBox1);
            this.Controls.Add(this.label1);
            this.Controls.Add(this.browse);
            this.Controls.Add(this.load);
            this.Controls.Add(this.textBox1);
            this.Name = "Step_LicenseFile";
            this.Size = new System.Drawing.Size(811, 531);
            this.SetActive += new System.ComponentModel.CancelEventHandler(this.Step_LicenseFile_SetActive);
            this.Controls.SetChildIndex(this.textBox1, 0);
            this.Controls.SetChildIndex(this.load, 0);
            this.Controls.SetChildIndex(this.browse, 0);
            this.Controls.SetChildIndex(this.label1, 0);
            this.Controls.SetChildIndex(this.richTextBox1, 0);
            this.Controls.SetChildIndex(this.Banner, 0);
            this.ResumeLayout(false);
            this.PerformLayout();

        }
        #endregion

        private void Step_LicenseFile_SetActive(object sender, System.ComponentModel.CancelEventArgs e)
        {
            SetWizardButtons(WizardButtons.Back | WizardButtons.Next);
        }

        private void load_Click(object sender, EventArgs e)
        {
            FileStream license_file_stream = new FileStream(this.textBox1.Text,FileMode.Open,FileAccess.Read);
            StreamReader license_file_reader = new StreamReader(license_file_stream);
            string license_file_content = license_file_reader.ReadToEnd();
            license_file_reader.Close();
            license_file_stream.Close();
            this.richTextBox1.Rtf = license_file_content;
        }

        private void browse_Click(object sender, EventArgs e)
        {
            OpenFileDialog open_license_file = new OpenFileDialog();

            if (Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI") == false)
            {
                open_license_file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }
            else
            {
                open_license_file.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\WAI";
            }

            open_license_file.Filter = "WAI files (*.rtf)|*.rtf";
            open_license_file.FilterIndex = 1;
            open_license_file.RestoreDirectory = true;
            open_license_file.Title = "Open License File (rtf)";

            if (open_license_file.ShowDialog() == DialogResult.OK)
            {
                this.textBox1.Text = open_license_file.FileName;
            }
        }
    }
}
